package leetcode.剑指offer.后40;

import org.junit.Test;

/**
 * @author :songyaozhang
 * @date :Created 2021/8/2 9:51
 * @description :https://leetcode-cn.com/problems/gu-piao-de-zui-da-li-run-lcof/
 */
public class 剑指_63_股票的最大利润 {
    @Test
    public void test() {
        Solution solution = new Solution();
        System.out.println(solution.maxProfit(new int[]{7,1,5,3,6,4}));

    }

    class Solution {
        public int maxProfit(int[] prices) {
            int min = Integer.MAX_VALUE;
            int profit = 0;
            for (int price : prices) {
                if (price > min) {
                    profit = Math.max(profit, price - min);
                } else
                    min = Math.min(min, price);
            }
            return profit;
        }
    }


}
